<template>
  <div class="home">
    <!-- 搜索框模块 -->
    <form action="/" class="nav">
      <van-search v-model="value" placeholder="请输入任务" @search="onSubmit(value)" :show-action="false" />
    </form>
    <!-- 内容模块 -->
    <div class="text_box">
      <div class="text" v-for="(item, index) in dataList" :key="index">
        <div class="left">
          <van-checkbox v-model="item.checked">{{ item.title }}</van-checkbox>
        </div>
        <div class="right">
          <van-icon name="cross" @click="deleted(index)" />
          <van-icon name="edit" @click="edit(index)" />
        </div>
      </div>

    </div>
    <div class="num" v-show="!total == ''">条目数：{{ total }}</div>
    <div>
      <input type="text" v-model="text" v-show="show">
    </div>
  </div>
</template>

<script>
import { ref, toRefs, reactive, onMounted } from "vue";
import typeIdea from "@/utils/idea";
import { Toast } from 'vant';
export default {
  name: "HomeView",
  components: {
  },
  setup() {
    const value = ref('');
    const count = ref(0);
    const total = ref('');
    const text = ref('')
    let dataList = []

    const onSubmit = (val) => {
      let data = {
        title: val,
        checked: false,
        id: ++count.value
      }
      dataList.push(data)
      total.value = dataList.length
      value.value = ""
    };
    const deleted = (index) => {
      dataList.splice(index, 1)
      value.value = null
    }
    const edit = (index) => {
      // console.log(text.value);
    }

    let obj = reactive({
      dataList
    });
    return {
      ...toRefs(obj),
      onSubmit,
      deleted,
      edit,
      value,
      count,
      total,
    };
  },
};
</script>
<style lang="scss" scoped>
.home {
  .text_box {
    min-height: 20px;

    .text {
      padding-bottom: 5px;
      border-bottom: 1px solid #ccc;
      margin: 20px;
      display: flex;
      justify-content: space-between;

      .left {}

      .right {}
    }
  }

  .num {
    margin: 20px;
  }
}
</style>
